﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace reseaux_neurones
{
    class Run
    {

        public static int NombreNeurones = 1;
        private int generationNumber = 2;
        public static Boolean debug = false;
        private double[] erreurs;


        public  void Apprentissage()
        {
            /* Choose a file for the learning and store it */
            string contentFile = Utilitaire.PickUpFileLearning();
            string[] lines = Utilitaire.ReadFileLearning(contentFile);

            Reseaux[] reseaux = new Reseaux[lines.Length];
            erreurs = new double[lines.Length];
            int line_number;
            double[][] apprentissage = new double[lines.Length][];


            /* foreach generation */
            for (int gen = 1; gen < generationNumber + 1; gen++)               
            {
                line_number = 0;
                foreach (string line in lines)
                {
                    
                    reseaux[line_number] = new Reseaux(NombreNeurones);
                    String[] input = line.Split(',');



                    /* For each neuronal TODO algo gen*/
                    for (int i = 0; i < NombreNeurones; i++)
                    {

                        /* for each line, for each neuronal we sent them the argument in order to calculate the final output */
                        reseaux[line_number].getHiddenNeuronal(i).setInputHidden(int.Parse(input[0]), int.Parse(input[1]), int.Parse(input[2]));
                        reseaux[line_number].getHiddenNeuronal(i).findPotentialHidden();
                        reseaux[line_number].getHiddenNeuronal(i).findHiddenOutput();

                    }
                    reseaux[line_number].getFinalNeuronal().setInputFinal(reseaux[line_number].getHiddenNeuronal());
                    reseaux[line_number].getFinalNeuronal().findPotentialFinal();
                    reseaux[line_number].getFinalNeuronal().findFinalOutput();
                    reseaux[line_number].getFinalNeuronal().findError(int.Parse(input[3]));
                    reseaux[line_number].setError(reseaux[line_number].getFinalNeuronal().getFinalError());
                    erreurs[line_number] = reseaux[line_number].getError();
                    //if (debug) System.Console.WriteLine("sortie neurone:" + reseaux[line_number].getFinalNeuronal().getSortieFinal() + " // Sortie attendu: " + input[3] + " // erreur : " + reseaux[line_number].getError());

                    line_number++;
                }

                reseaux = Utilitaire.Sort(reseaux);
                
            }

        }
    }
}
